package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.StudentVacationService;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @描述 班牌和家长端小程序 请假接口
 * @创建人 zm
 * @创建时间 2020/3/26
 */
@RestController
@RequestMapping("/brands")
public class StudentVacationController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private StudentVacationService service;


    /**
     * @描述 根据学生id查询学生请假信息情况(家长端请假和班牌学生中心请假)
     * @创建人 zm
     * @创建时间 2020/3/26
     */
    @RequestMapping("/queryStudentVacationById")
    public Result queryStudentVacationById(@RequestParam(value = "id") Integer id) {
        logger.info("StudentVacationController==>queryStudentVacationById,id={}", id);
        return new Result(service.queryStudentVacationById(id));
    }

    /**
     * @描述 修改请假状态
     * @创建人 zm
     * @创建时间 2020/3/26
     */
    @RequestMapping("/updateStudentVacationState")
    public Result updateStudentVacationState(@RequestParam(value = "id") Integer id,
                                             @RequestParam(value = "state") Integer state) {
        logger.info("VacationController==>updateStudentVacationState,id={},state={},teacherId={}", id, state);
        return service.updateStudentVacationState(id, state);
    }


    /**
     * @描述 根据班级id查班主任信息(家长端请假和班牌学生中心请假)
     * @创建人 zm
     * @创建时间 2020/3/27
     */
    @RequestMapping("/queryHeadMaster")
    public Result queryHeadMaster(@RequestParam(value = "classId") Integer classId) {
        logger.info("StudentVacationController==>queryHeadMaster,id={}", classId);
        return new Result(service.queryHeadMaster(classId));
    }


    /**
     * @描述 添加请假信息(家长端请假和班牌学生中心请假)
     * @创建人 zm
     * @创建时间 2020/3/26
     */
    @RequestMapping("/addStudentVacation")
    public Result addStudentVacation(@RequestParam(value = "id") Integer id,//学生id
                                     @RequestParam(value = "school_id") Integer school_id,//学校id
                                     @RequestParam(value = "stime") String stime,//开始时间
                                     @RequestParam(value = "etime") String etime,//结束时间
                                     @RequestParam(value = "content", required = false) String content,//请假理由
                                     @RequestParam(value = "type") Integer type) {//type  0 病假 1 事假
        logger.info("StudentVacationController==>addStudentVacation");
        long l = service.addStudentVacation(id, school_id, stime, etime, content, type);
        if (l > 0) {
            return new Result();
        }
        return new Result(CodeUtil.ADD_FAILURE);
    }


    /**
     * @描述 撤销请假(家长端请假和班牌学生中心请假)
     * @创建人 zm
     * @创建时间 2020/3/27
     */
    @RequestMapping("/delStudentVacation")
    public Result delStudentVacation(@RequestParam(value = "id") Integer id) {//请假信息id
        logger.info("StudentVacationController==>delStudentVacation");
        long l = service.delStudentVacation(id);
        if (l > 0) {
            return new Result();
        }
        return new Result(CodeUtil.DELETE_FAILED);
    }

    /**
     * @描述 查该班级所有通知
     * @创建人 zm
     * @创建时间 2020/4/1
     */
    @RequestMapping("/queryClassNotice")
    public Result queryClassNotice(@RequestParam(value = "classId") Integer classId,
                                   @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                   @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {//班级通知
        logger.info("StudentVacationController==>queryClassNotice");
        return service.queryClassNotice(classId, indexNo, rows);
    }

    /**
     * @描述 根据班级查所有图片
     * @创建人 zm
     * @创建时间 2020/4/1
     */
    @RequestMapping("/queryClassPicturesAll")
    public Result queryClassPicturesAll(@RequestParam(value = "classId") Integer classId,
                                        @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                        @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {//班级通知
        logger.info("StudentVacationController==>queryClassPicturesAll");
        return service.queryClassPicturesAll(classId, indexNo, rows);
    }

    /**
     * @描述 根据班级查所有视频
     * @创建人 zm
     * @创建时间 2020/4/1
     */
    @RequestMapping("/queryClassVideosAll")
    public Result queryClassVideosAll(@RequestParam(value = "classId") Integer classId,
                                      @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                      @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {//班级通知
        logger.info("StudentVacationController==>queryClassVideosAll");
        return service.queryClassVideosAll(classId, indexNo, rows);
    }

    /**
     * @描述 家长端查询学生成绩
     * @创建人 zm
     * @创建时间 2020/4/22
     */
    @RequestMapping("/queryStudentAchievement")
    public Result queryStudentAchievement(@RequestParam(value = "id") Integer id) {//学生id
        logger.info("根据学生id查询学生成绩");
        return service.queryStudentAchievement(id);
    }

}
